package com.yl.demo.web.controller;

import com.yl.demo.model.YlUserInfoModel;
import com.yl.demo.service.UserService;
import com.yl.demo.web.HelloController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yl.db_core.base.BaseDao;
import org.yl.db_core.utils.constant.SqlConstant;

import java.util.List;

/**
 * @Description: 用户信息
 * @Author: YL
 * @CreateDate: 2018/10/24 14:24
 * @Version: 1.0
 */

@RestController
@RequestMapping("/userInfo/*")
public class UserController {

    private final static Logger logger = LoggerFactory.getLogger(HelloController.class);

    @Autowired
    UserService userService;

    @Autowired
    BaseDao baseDao;

    /**
     * 用户查询.
     *
     * @return
     */
    @RequestMapping("/userList")
    public String userInfo() {
        logger.info("用户查询--userList");
        return "userInfo";
    }


    /**
     * 用户添加;
     *
     * @return
     */
    @RequestMapping("/userAdd")
    @RequiresRoles(value = {"user", "admin"})
    @RequiresPermissions(value = "userInfo:add")//权限管理;
    public String userInfoAdd() {
        logger.info("用户添加--userAdd");
        return "userInfoAdd";
    }

    /**
     * 用户删除;
     *
     * @return
     */
    @RequestMapping("/userDel")
    @RequiresRoles(value = {"admin"})
    @RequiresPermissions(value = "userInfo:del")//权限管理;
    public String userDel() {
        logger.info("用户删除--userDel");
        return "userInfoDel";
    }

    @RequestMapping("/userInfoList")
    public List findUserInfoList() {
        YlUserInfoModel userInfoModel = new YlUserInfoModel();
        List list = baseDao.queryByList(userInfoModel, SqlConstant.SELECT_LIST, new BeanPropertyRowMapper(YlUserInfoModel.class), 1, 10);
        return list;
    }

}
